<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!--  获取URL参数, 并转换为对象类型 -->
</head>
<body>
  <script>
  function urlToObj(str){
    var obj = {};
    var arr1 = str.split("?");
    var arr2 = arr1[1].split("&");
    for(var i=0 ; i < arr2.length; i++){
      var res = arr2[i].split("=");
      obj[res[0]] = res[1];
    }
    return obj;
  }
  console.log(urlToObj('https://www.baidu.com/s?ie=utf-8&f=3&rsv_bp=1&tn=baidu&wd=%E7%99%BE%E5%BA%A6'))
  //{ie: "utf-8", f: "3", rsv_bp: "1", tn: "baidu", wd: "%E7%99%BE%E5%BA%A6"}
  </script>
</body>
</html>